import {mainNetWork} from "./env"
import { ethers, providers, utils } from "ethers";
export async function callStatic() {
    const main = async () => {
      // 1. 创建主网的 provider 
      const provider = new ethers.providers.JsonRpcProvider(mainNetWork)
      // 利用私钥和provider创建wallet对象
      const privateKey = '5e34716a60a0926d67c629fae8752cdc9fbe742095a093d40e5b1a2834cc981e'
      const wallet = new ethers.Wallet(privateKey, provider)
      // 3. 创建合约实例
      const addressDAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // DAI Contract
      // DAI的ABI
      const abiDAI = [
        "function balanceOf(address) public view returns(uint)",
        "function transfer(address, uint) public returns (bool)",
      ];
      // 创建DAI合约实例
      const contractDAI = new ethers.Contract(addressDAI, abiDAI, provider)
      const walletAddress1 = wallet.address
      const walletAddress2 = await wallet.getAddress()
      console.log('walletAddress1',walletAddress1)
      console.log('walletAddress2',walletAddress2)
      const balanceOf =  await contractDAI.balanceOf(walletAddress1)
      console.log('查询转帐前钱包余额',ethers.utils.formatEther(balanceOf))
      const tx = await contractDAI.callStatic.transfer('vitalik.eth', ethers.utils.parseEther("10000"), {from: '0x23613Dd16Bf1A3C3fE92a7e46bCa7BE5C99ED5C0'})
      console.log('交易会成功吗？', tx)
    }
    main()
}